home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2003 December / The Sunday Times - The Month 2003-12.iso / mac / The Month DEC 03 / engine / modules / text.swf / scripts / FScrollBarSymbol.as next >
Text File  |  2003-11-10  |  12KB  |  382 lines

  1. FScrollBarClass = function()
  2. {
  3.    if(this._height == 4)
  4.    {
  5.       return undefined;
  6.    }
  7.    this.init();
  8.    this.minPos = this.maxPos = this.pageSize = this.largeScroll = 0;
  9.    this.smallScroll = 1;
  10.    this.width = !this.horizontal ? this._height : this._width;
  11.    this._xscale = this._yscale = 100;
  12.    this.setScrollPosition(0);
  13.    this.tabEnabled = false;
  14.    if(this._targetInstanceName.length > 0)
  15.    {
  16.       this.setScrollTarget(this._parent[this._targetInstanceName]);
  17.    }
  18.    this.tabChildren = false;
  19.    this.setSize(this.width);
  20. };
  21. FScrollBarClass.prototype = new FUIComponentClass();
  22. FScrollBarClass.prototype.setHorizontal = function(flag)
  23. {
  24.    if(this.horizontal && !flag)
  25.    {
  26.       this._xscale = 100;
  27.       this._rotation = 0;
  28.    }
  29.    else if(flag && !this.horizontal)
  30.    {
  31.       this._xscale = -100;
  32.       this._rotation = -90;
  33.    }
  34.    this.horizontal = flag;
  35. };
  36. FScrollBarClass.prototype.setScrollProperties = function(pSize, mnPos, mxPos)
  37. {
  38.    if(!this.enable)
  39.    {
  40.       return undefined;
  41.    }
  42.    this.pageSize = pSize;
  43.    this.minPos = Math.max(mnPos,0);
  44.    this.maxPos = Math.max(mxPos,0);
  45.    this.scrollPosition = Math.max(this.minPos,this.scrollPosition);
  46.    this.scrollPosition = Math.min(this.maxPos,this.scrollPosition);
  47.    if(this.maxPos - this.minPos <= 0)
  48.    {
  49.       this.scrollThumb_mc.removeMovieClip();
  50.       this.upArrow_mc.gotoAndStop(3);
  51.       this.downArrow_mc.gotoAndStop(3);
  52.       this.downArrow_mc.onPress = this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = null;
  53.       this.upArrow_mc.onPress = this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = null;
  54.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onRelease = null;
  55.       this.scrollTrack_mc.onDragOut = this.scrollTrack_mc.onRollOut = null;
  56.       this.scrollTrack_mc.useHandCursor = false;
  57.    }
  58.    else
  59.    {
  60.       var tmp = this.getScrollPosition();
  61.       this.downArrow_mc.onRollOver = function()
  62.       {
  63.          this.gotoAndStop(2);
  64.       };
  65.       this.downArrow_mc.onRollOut = function()
  66.       {
  67.          this.gotoAndStop(1);
  68.       };
  69.       this.upArrow_mc.onRollOver = function()
  70.       {
  71.          this.gotoAndStop(2);
  72.       };
  73.       this.upArrow_mc.onRollOut = function()
  74.       {
  75.          this.gotoAndStop(1);
  76.       };
  77.       this.upArrow_mc.onPress = this.upArrow_mc.onDragOver = this.startUpScroller;
  78.       this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = this.stopScrolling;
  79.       this.downArrow_mc.onPress = this.downArrow_mc.onDragOver = this.startDownScroller;
  80.       this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = this.stopScrolling;
  81.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onDragOver = this.startTrackScroller;
  82.       this.scrollTrack_mc.onRelease = this.stopScrolling;
  83.       this.scrollTrack_mc.onDragOut = this.stopScrolling;
  84.       this.scrollTrack_mc.onRollOut = this.stopScrolling;
  85.       this.attachMovie("ScrollThumb","scrollThumb_mc",3);
  86.       this.scrollThumb_mc.onRollOver = function()
  87.       {
  88.          this.mc_sliderMid.gotoAndStop(10);
  89.       };
  90.       this.scrollThumb_mc.onRollOut = function()
  91.       {
  92.          this.mc_sliderMid.gotoAndStop(1);
  93.       };
  94.       this.scrollThumb_mc._x = 0;
  95.       this.scrollThumb_mc._y = this.upArrow_mc._height;
  96.       this.scrollThumb_mc.onPress = this.startDragThumb;
  97.       this.scrollThumb_mc.controller = this;
  98.       this.scrollThumb_mc.onRelease = this.scrollThumb_mc.onReleaseOutside = this.stopDragThumb;
  99.       this.thumbHeight = this.pageSize / (this.maxPos - this.minPos + this.pageSize) * this.trackSize;
  100.       this.thumbMid_mc = this.scrollThumb_mc.mc_sliderMid;
  101.       this.thumbTop_mc = this.scrollThumb_mc.mc_sliderTop;
  102.       this.thumbBot_mc = this.scrollThumb_mc.mc_sliderBot;
  103.       this.thumbHeight = Math.max(this.thumbHeight,6);
  104.       this.midHeight = this.thumbHeight - this.thumbTop_mc._height - this.thumbBot_mc._height;
  105.       this.thumbMid_mc._yScale = this.midHeight * 100 / this.thumbMid_mc._height;
  106.       this.thumbMid_mc._y = this.thumbTop_mc._height;
  107.       this.thumbBot_mc._y = this.thumbTop_mc._height + this.midHeight;
  108.       this.scrollTop = this.scrollThumb_mc._y;
  109.       this.trackHeight = this.trackSize - this.thumbHeight;
  110.       this.scrollBot = this.trackHeight + this.scrollTop;
  111.       tmp = Math.min(tmp,this.maxPos);
  112.       this.setScrollPosition(Math.max(tmp,this.minPos));
  113.    }
  114. };
  115. FScrollBarClass.prototype.getScrollPosition = function()
  116. {
  117.    return this.scrollPosition;
  118. };
  119. FScrollBarClass.prototype.setScrollPosition = function(pos)
  120. {
  121.    this.scrollPosition = pos;
  122.    if(this.scrollThumb_mc != undefined)
  123.    {
  124.       pos = Math.min(pos,this.maxPos);
  125.       pos = Math.max(pos,this.minPos);
  126.    }
  127.    this.scrollThumb_mc._y = (pos - this.minPos) * this.trackHeight / (this.maxPos - this.minPos) + this.scrollTop;
  128.    this.executeCallBack();
  129. };
  130. FScrollBarClass.prototype.setLargeScroll = function(lScroll)
  131. {
  132.    this.largeScroll = lScroll;
  133. };
  134. FScrollBarClass.prototype.setSmallScroll = function(sScroll)
  135. {
  136.    this.smallScroll = sScroll;
  137. };
  138. FScrollBarClass.prototype.setEnabled = function(enabledFlag)
  139. {
  140.    var wasEnabled = this.enable;
  141.    if(enabledFlag && !wasEnabled)
  142.    {
  143.       this.enable = enabledFlag;
  144.       if(this.textField != undefined)
  145.       {
  146.          this.setScrollTarget(this.textField);
  147.       }
  148.       else
  149.       {
  150.          this.setScrollProperties(this.pageSize,this.cachedMinPos,this.cachedMaxPos);
  151.          this.setScrollPosition(this.cachedPos);
  152.       }
  153.       this.clickFilter = undefined;
  154.    }
  155.    else if(!enabledFlag && wasEnabled)
  156.    {
  157.       this.textField.removeListener(this);
  158.       this.cachedPos = this.getScrollPosition();
  159.       this.cachedMinPos = this.minPos;
  160.       this.cachedMaxPos = this.maxPos;
  161.       if(this.clickFilter == undefined)
  162.       {
  163.          this.setScrollProperties(this.pageSize,0,0);
  164.       }
  165.       else
  166.       {
  167.          this.clickFilter = true;
  168.       }
  169.       this.enable = enabledFlag;
  170.    }
  171. };
  172. FScrollBarClass.prototype.setSize = function(hgt)
  173. {
  174.    if(this._height == 1)
  175.    {
  176.       return undefined;
  177.    }
  178.    this.width = hgt;
  179.    this.scrollTrack_mc._yscale = 100;
  180.    this.scrollTrack_mc._yscale = 100 * this.width / this.scrollTrack_mc._height;
  181.    if(this.upArrow_mc == undefined)
  182.    {
  183.       this.attachMovie("UpArrow","upArrow_mc",1);
  184.       this.attachMovie("DownArrow","downArrow_mc",2);
  185.       this.downArrow_mc.controller = this.upArrow_mc.controller = this;
  186.       this.upArrow_mc._x = this.upArrow_mc._y = 0;
  187.       this.downArrow_mc._x = 0;
  188.    }
  189.    this.scrollTrack_mc.controller = this;
  190.    this.downArrow_mc._y = this.width - this.downArrow_mc._height;
  191.    this.trackSize = this.width - 2 * this.downArrow_mc._height;
  192.    if(this.textField != undefined)
  193.    {
  194.       this.onTextChanged();
  195.    }
  196.    else
  197.    {
  198.       this.setScrollProperties(this.pageSize,this.minPos,this.maxPos);
  199.    }
  200. };
  201. FScrollBarClass.prototype.scrollIt = function(inc, mode)
  202. {
  203.    var delt = this.smallScroll;
  204.    if(inc != "one")
  205.    {
  206.       delt = this.largeScroll != 0 ? this.largeScroll : this.pageSize;
  207.    }
  208.    var newPos = this.getScrollPosition() + mode * delt;
  209.    if(newPos > this.maxPos)
  210.    {
  211.       newPos = this.maxPos;
  212.    }
  213.    else if(newPos < this.minPos)
  214.    {
  215.       newPos = this.minPos;
  216.    }
  217.    this.setScrollPosition(newPos);
  218. };
  219. FScrollBarClass.prototype.startDragThumb = function()
  220. {
  221.    this.lastY = this._ymouse;
  222.    this.onMouseMove = this.controller.dragThumb;
  223. };
  224. FScrollBarClass.prototype.dragThumb = function()
  225. {
  226.    this.scrollMove = this._ymouse - this.lastY;
  227.    this.scrollMove += this._y;
  228.    if(this.scrollMove < this.controller.scrollTop)
  229.    {
  230.       this.scrollMove = this.controller.scrollTop;
  231.    }
  232.    else if(this.scrollMove > this.controller.scrollBot)
  233.    {
  234.       this.scrollMove = this.controller.scrollBot;
  235.    }
  236.    this._y = this.scrollMove;
  237.    var c = this.controller;
  238.    c.scrollPosition = Math.round((c.maxPos - c.minPos) * (this._y - c.scrollTop) / c.trackHeight) + c.minPos;
  239.    this.controller.isScrolling = true;
  240.    updateAfterEvent();
  241.    this.controller.executeCallBack();
  242. };
  243. FScrollBarClass.prototype.stopDragThumb = function()
  244. {
  245.    this.controller.isScrolling = false;
  246.    this.onMouseMove = null;
  247. };
  248. FScrollBarClass.prototype.startTrackScroller = function()
  249. {
  250.    this.controller.trackScroller();
  251.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"page",-1);
  252. };
  253. FScrollBarClass.prototype.scrollInterval = function(inc, mode)
  254. {
  255.    clearInterval(this.scrolling);
  256.    if(inc == "page")
  257.    {
  258.       this.trackScroller();
  259.    }
  260.    else
  261.    {
  262.       this.scrollIt(inc,mode);
  263.    }
  264.    this.scrolling = setInterval(this,"scrollInterval",35,inc,mode);
  265. };
  266. FScrollBarClass.prototype.trackScroller = function()
  267. {
  268.    if(this.scrollThumb_mc._y + this.thumbHeight < this._ymouse)
  269.    {
  270.       this.scrollIt("page",1);
  271.    }
  272.    else if(this.scrollThumb_mc._y > this._ymouse)
  273.    {
  274.       this.scrollIt("page",-1);
  275.    }
  276. };
  277. FScrollBarClass.prototype.stopScrolling = function()
  278. {
  279.    this.controller.downArrow_mc.gotoAndStop(1);
  280.    this.controller.upArrow_mc.gotoAndStop(1);
  281.    clearInterval(this.controller.scrolling);
  282. };
  283. FScrollBarClass.prototype.startUpScroller = function()
  284. {
  285.    this.controller.upArrow_mc.gotoAndStop(2);
  286.    this.controller.scrollIt("one",-1);
  287.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",-1);
  288. };
  289. FScrollBarClass.prototype.startDownScroller = function()
  290. {
  291.    this.controller.downArrow_mc.gotoAndStop(2);
  292.    this.controller.scrollIt("one",1);
  293.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",1);
  294. };
  295. FScrollBarClass.prototype.setScrollTarget = function(tF)
  296. {
  297.    if(tF == undefined)
  298.    {
  299.       this.textField.removeListener(this);
  300.       delete this.textField[!this.horizontal ? "vScroller" : "hScroller"];
  301.       if(this.textField.hScroller != undefined && this.textField.vScroller != undefined)
  302.       {
  303.          this.textField.unwatch("text");
  304.          this.textField.unwatch("htmltext");
  305.       }
  306.    }
  307.    this.textField = undefined;
  308.    if(!(tF instanceof TextField))
  309.    {
  310.       return undefined;
  311.    }
  312.    this.textField = tF;
  313.    this.textField[!this.horizontal ? "vScroller" : "hScroller"] = this;
  314.    this.onTextChanged();
  315.    this.onChanged = function()
  316.    {
  317.       this.onTextChanged();
  318.    };
  319.    this.onScroller = function()
  320.    {
  321.       if(!this.isScrolling)
  322.       {
  323.          if(!this.horizontal)
  324.          {
  325.             this.setScrollPosition(this.textField.scroll);
  326.          }
  327.          else
  328.          {
  329.             this.setScrollPosition(this.textField.hscroll);
  330.          }
  331.       }
  332.    };
  333.    this.textField.addListener(this);
  334.    this.textField.watch("text",this.callback);
  335.    this.textField.watch("htmlText",this.callback);
  336. };
  337. FScrollBarClass.prototype.callback = function(prop, oldVal, newVal)
  338. {
  339.    clearInterval(this.hScroller.synchScroll);
  340.    clearInterval(this.vScroller.synchScroll);
  341.    this.hScroller.synchScroll = setInterval(this.hScroller,"onTextChanged",50);
  342.    this.vScroller.synchScroll = setInterval(this.vScroller,"onTextChanged",50);
  343.    return newVal;
  344. };
  345. FScrollBarClass.prototype.onTextChanged = function()
  346. {
  347.    if(!this.enable || this.textField == undefined)
  348.    {
  349.       return undefined;
  350.    }
  351.    clearInterval(this.synchScroll);
  352.    if(this.horizontal)
  353.    {
  354.       var pos = this.textField.hscroll;
  355.       this.setScrollProperties(this.textField._width,0,this.textField.maxhscroll);
  356.       this.setScrollPosition(Math.min(pos,this.textField.maxhscroll));
  357.    }
  358.    else
  359.    {
  360.       var pos = this.textField.scroll;
  361.       var pageSize = this.textField.bottomScroll - this.textField.scroll;
  362.       this.setScrollProperties(pageSize,1,this.textField.maxscroll);
  363.       this.setScrollPosition(Math.min(pos,this.textField.maxscroll));
  364.    }
  365. };
  366. FScrollBarClass.prototype.executeCallBack = function()
  367. {
  368.    if(this.textField == undefined)
  369.    {
  370.       super.executeCallBack();
  371.    }
  372.    else if(this.horizontal)
  373.    {
  374.       this.textField.hscroll = this.getScrollPosition();
  375.    }
  376.    else
  377.    {
  378.       this.textField.scroll = this.getScrollPosition();
  379.    }
  380. };
  381. Object.registerClass("FScrollBarSymbol",FScrollBarClass);
  382.